package com.digitalchina.lxnsy.activity.farmVideo;

import android.webkit.JavascriptInterface;

import com.baoyz.actionsheet.ActionSheet;
import com.digitalchina.lxnsy.base.BaseHtmlActivity;
import com.digitalchina.lxnsy.constant.URL;
import com.digitalchina.lxnsy.entity.PayVO;
import com.digitalchina.lxnsy.toolkit.JointImageUrl;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.digitalchina.lxnsy.wxapi.WXPayEntryActivity;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * ================================================
 * 项目名称：android
 * 类描述：农技视频详情
 * 创建人：yzm
 * 创建时间：2020/1/8 17:26
 * 修改备注：
 * ================================================
 */
public class VideoDetailActivity extends BaseHtmlActivity {

    @Override
    protected void loadHtml() {
        webView.addJavascriptObject(new JsApi(), null);
        loadUrl("video-video-details");
        setTitle("视频详情");
        setRightText("更多");
    }

    @Override
    public void rightOnClick() {
        ActionSheet.createBuilder(this, getSupportFragmentManager())
                .setCancelButtonTitle("取消")
                .setOtherButtonTitles("收藏", "分享")
                .setCancelableOnTouchOutside(true)
                .setListener(new ActionSheet.ActionSheetListener() {
                    @Override
                    public void onDismiss(ActionSheet actionSheet, boolean isCancel) {

                    }

                    @Override
                    public void onOtherButtonClick(ActionSheet actionSheet, int index) {
                        switch (index) {
                            case 0:
                                callJsMethod("store");
                                break;
                            case 1:
                                callJsMethod("share");
                                break;
                        }
                    }
                }).show();
    }

    public class JsApi {
        //去个人主页
        @JavascriptInterface
        public void toPersonHomePage(Object msg) {
            go(PersonActivity.class);
        }

        //去评论
        @JavascriptInterface
        public void goEvalOper(Object msg) {
            go(CommentActivity.class);
        }

        //分享
        @JavascriptInterface
        public void share(Object msg) {

        }

        //购买视频
        @JavascriptInterface
        public void buy(Object msg) {
            String[] s = msg.toString().split("&");
            PayVO payVO = new PayVO();
            payVO.setPrice(s[1]);
            payVO.setOrderNO(s[0]);
            payVO.setGoodsName("付费视频购买");
            payVO.setType(5);
            go(WXPayEntryActivity.class, "payVO", payVO);
        }

    }
}
